<?php

session_start();
   $list = $_SESSION['list']; 


$conn = mysql_connect('studentdb.gl.umbc.edu', 'chrimo1', 'chrimo1');
if (!$conn) {
   die('Could not connect');
}

$db_selected = mysql_select_db('chrimo1', $conn);
if (!$db_selected) {
   die ('Can\'t use chrimo1');
}
echo '<body style="background-color:black">';
$id = $_POST['idNum'];
$sql = "SELECT * FROM gameInventory WHERE idNum='$id'";
$getResult = mysql_query($sql, $conn);
if (mysql_num_rows($getResult) == 0 ) {
   
   echo '<center><h1 style="color:red; font-size: 42" >The Game you requested is not in Inventory!</h1></center>';
   echo '<form method="get"  action="listInventory.php">'; 
      echo '<input type="hidden" name="choice" value="'; echo $list;echo '">';
      echo '<center><input type="image" name="submit" src="images/back_button.png" border="0"></center>';
    echo '</form>';
   echo '<center><h2><a style="color:gold" href="admin.html"><img src="images/admin_button.png"></a></h2></center><br/>';
   die();
}



if($_POST['delete']){
   
   
   mysql_query("DELETE from gameInventory WHERE idNum='$id'");
   echo '<center><img src="images/zelda_link_animated.gif" alt="Link" /></center>';
   echo '<center><h1 style="color:green; font-size: 42">Game deleted from Inventory</h1></center>';
   echo '<form method="get"  action="listInventory.php">'; 
      echo '<input type="hidden" name="choice" value="'; echo $list;echo '">';
      echo '<center><input type="image" name="submit" src="images/Continue.PNG" border="0"></center>';
   echo '</form>';
   echo '<center><h2><a style="color:gold" href="admin.html"><img src="images/admin_button.png"></a></h2></center><br/>';
   exit;
}
else{


   $result = mysql_fetch_array($getResult);

   $gameName = $result['gameName'];
   $developer = $result['developer'];
   $releaseDate = $result['releaseDate'];
   $description = $result['description'];
   $quantity = $result['quantity'];
   $price = $result['price'];
   $imageURL = $result['imageURL'];
   $system = $result['system'];
   $multiplayer = $result['multiplayer'];
   $singleplayer = $result['singleplayer'];
   $cooperative = $result['cooperative'];
   $beatemUp = $result['beatemUp'];
   $rpg = $result['rpg'];
   $platform = $result['platform'];
   $action = $result['action'];
   $strategy = $result['strategy'];
   $shootemUp = $result['shootemUp'];
   $buildingSim = $result['buildingSim'];
   $scrollingShooter = $result['scrollingShooter'];
   $racing = $result['racing'];
   $sports = $result['sports'];

}

?>

<html>
   <head>
      <style type="text/css">

        body{
	  background-color: black;
          color: gold;
          font-size: 14pt;
        }
	 
	 .container {
	   clear: both;
	 }
	 .boxLeft {
	   float: left;
	   
	   
	 }
	
	 .boxRight {
	   float: right;
	   
	 }
      </style>

      <div class_"container">
	 <div class="boxLeft">
	   <form method="get"  action="listInventory.php"> 
          <input type="hidden" name="choice" value="<? echo $list; ?>">
          <input type="image" name="submit" src="images/back_button.PNG" border="0">
          </form>
	 </div>
        <div class="boxRight">
	   <a style="color:gold" href="admin.html"><img src="images/admin_button.png"></a>
	 </div>
      </div>
      

   </head>
   <body>
</br>
<center><h1>Edit Game</h1></center>
      

<form action="updateInventory.php" method="post">
   <input type="hidden" name="choice" value="<? echo $list; ?>">
   <input type="hidden" name="idNum" value="<?php echo $id; ?>" >
   <input type="hidden" name="gameName" value="<?php echo $gameName; ?>" >
   <h3>Game Name</h3>
   <h4 style="color:red"><? echo $gameName; ?></h4>

   <h3>Select the System</h3>
   <?php
	if($system == "sega"){
	   echo '<input type="radio" name="system" value="sega" checked="checked"/>';
	   echo 'Sega Genesis<br/>';
	   echo '<input type="radio" name="system" value="snes"/>';
      	   echo 'Super Nintendo<br/>';
	}
	elseif($system == "snes"){
	   echo '<input type="radio" name="system" value="sega"/>';
	   echo 'Sega Genesis<br/>';
          echo '<input type="radio" name="system" value="snes" checked="checked"/>';
      	   echo 'Super Nintendo<br/>';
	}
	
   ?>

   <h3>Enter Developers Name</h3>
   <input type="varchar" size="75" name="developer" value="<? echo $developer; ?>"/>
	
   <h3>Select the year the game was released</h3>
      <select name="releaseDate">
      <option value="<? echo $releaseDate; ?>" ><? echo $releaseDate; ?></option>
      <option value="1990">1990</option>
      <option value="1991">1991</option>
      <option value="1992">1992</option>
      <option value="1993">1993</option>
      <option value="1994">1994</option>
      <option value="1995">1995</option>
      <option value="1996">1996</option>
      <option value="1997">1997</option>
      </select>


   <h3>Game Description</h3>
   <textarea cols="80" rows="10" name="description" ><?php echo $description; ?></textarea>

   <h3>Select the Genre(s)</h3>
   <?php
	if($beatemUp == 1){
	   echo '<input type="checkbox" name="beatemUp" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="beatemUp" value="1" />'; 
	}
	echo 'Beat\'em Up<br/>';

	if($rpg == 1){
	   echo '<input type="checkbox" name="rpg" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="rpg" value="1" />'; 
	}
	echo 'RPG<br/>';

	if($platform == 1){
	   echo '<input type="checkbox" name="platform" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="platform" value="1" />'; 
	}
	echo 'Platform<br/>';

	if($action == 1){
	   echo '<input type="checkbox" name="action" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="action" value="1" />'; 
	}
	echo 'Action<br/>';

	if($strategy == 1){
	   echo '<input type="checkbox" name="strategy" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="strategy" value="1" />'; 
	}
	echo 'Strategy/Puzzle<br/>';

	if($shootemUp == 1){
	   echo '<input type="checkbox" name="shootemUp" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="shootemUp" value="1" />'; 
	}
	echo 'Shoot\'em Up<br/>';

   	if($buildingSim == 1){
	   echo '<input type="checkbox" name="buildingSim" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="buildingSim" value="1" />'; 
	}
	echo 'City Building Simulator<br/>';

	if($scrollingShooter == 1){
	   echo '<input type="checkbox" name="scrollingShooter" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="scrollingShooter" value="1" />'; 
	}
	echo 'Scrolling Shooter<br/>';

	if($racing == 1){
	   echo '<input type="checkbox" name="racing" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="racing" value="1" />'; 
	}
	echo 'Racing<br/>';

	if($sports == 1){
	   echo '<input type="checkbox" name="sports" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="sports" value="1" />'; 
	}
	echo 'Sports<br/>';

	echo '<h3>Select Player Mode(s)</h3>';

	if($singleplayer== 1){
	   echo '<input type="checkbox" name="singleplayer" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="singleplayer" value="1" />'; 
	}
	echo 'Single-player<br/>';

	if($multiplayer== 1){
	   echo '<input type="checkbox" name="multiplayer" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="multiplayer" value="1" />'; 
	}
	echo 'Multiplayer<br/>';

	if($cooperative== 1){
	   echo '<input type="checkbox" name="cooperative" value="1" checked="checked"/>'; 
	}
	else{
	   echo '<input type="checkbox" name="cooperative" value="1" />'; 
	}
	echo 'Cooperative<br/>';
   ?>

   <h3>Enter Price</h3>
   $<input type="decimal" size="10" name="price" value="<? echo $price; ?>"/>

   <h3>Enter Quantity in Stock</h3>
   <input type="tinyint" size="8" name="quantity" value="<? echo $quantity; ?>"/>
   
   <h3>Copy & Paste Image URL Here</h3>
   <input type="varchar" size="75" name="imageURL" value="<? echo $imageURL; ?>" /></br></br>
   <img src="<? echo $imageURL; ?>" alt="Game Image" />


   </br>
   </br>

 
   <input type="image" name="submit" src="images/save_button.PNG" border="0">   
</form>
	
   </body>
</html>
